module.exports = {
	data() {
		return {
			current_hash: localStorage.getItem('appHashes') || '',
			new_hash: '',
      messageShow: false
		}
	},
	created() {
		if (process.env.NODE_ENV !== 'development') {
			this.checkVersion()
		}
	},
	methods: {
		checkVersion() {
      const self = this
      this.messageShow = false
			try {
				fetch(`${window.location.origin}/devops/f/cicd/version.json?date=${Date.now()}`, { cache: 'no-store' })
					.then(response => response.json())
					.then(res => {
						self.new_hash = res.hashCommit
						if (self.new_hash !== self.current_hash) {
							localStorage.setItem('appHashes', self.new_hash)
              self.$message({
                type: 'success',
                message: '有新版本更新啦~请刷新页面查看最新内容',
                duration: 0,
                showClose: true
              })
              self.messageShow = true
						}
					})
			} catch (error) {
				console.error('获取版本信息失败:', error)
			}
		}
	}
}
